/**
 * 格式化存储空间
 * @param {number} bytes 字节数
 * @returns {string} 格式化后的存储空间
 */
export function formatStorage(bytes) {
  if (typeof bytes !== 'number' || isNaN(bytes)) {
    bytes = 0;
  }
  
  const units = ['B', 'KB', 'MB', 'GB', 'TB'];
  let size = bytes;
  let unitIndex = 0;
  
  while (size >= 1024 && unitIndex < units.length - 1) {
    size /= 1024;
    unitIndex++;
  }
  
  return size.toFixed(2) + ' ' + units[unitIndex];
} 